package com.xiaomili.halfsugar.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xiaomili.halfsugar.FlowLayout;
import com.xiaomili.halfsugar.R;


/**
 * 搜索页面---点击搜索框的碎片
 * A simple {@link Fragment} subclass.
 */
public class SearchClickFragment extends Fragment {
    private String[]data={"手机壳","宿舍","手表","泳衣","钱包","充电宝","性冷淡","口红","双肩包","杯子",
            "防晒","手链","耳机","伞","礼物"};
    private TextView textView;

    public SearchClickFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_search_click, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        FlowLayout flowLayout= (FlowLayout) view.findViewById(R.id.search_click_label);
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(//设置流布局里面的Margin值
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = 26;
        lp.topMargin = 17;
        for (int i = 0; i < data.length; i++) {
            textView = new TextView(getContext());
            textView.setText(data[i]);
            textView.setBackground(getResources().getDrawable(R.drawable.search_click_text));
            textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            flowLayout.addView(textView,lp);
        }

    }
}
